/**
 * 
 */
package leetCode;

import java.util.Arrays;

/**
 * @author zhongfang
 *
 */
public class shortestUnsortedContinuousSubarray {
	
    public static int findUnsortedSubarray(int[] nums) {
    	int[] b=Arrays.copyOf(nums,nums.length);
    	Arrays.sort(b);
    	int i=0,j=b.length-1;
    	while (i<=j&&nums[i]==b[i]) {
			i++;
		}
    	if(i<j){
    		while (nums[j]==b[j]) {
				j--;
			}
    	}
        return j-i+1;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] a={2,4,6,7,9, 15};
		System.out.println(findUnsortedSubarray(a));
	}

}
